package com.qgs.secsgem.mq.consumer;


import com.qgs.secsgem.mq.configuration.ConfigOfDeadLetterQueue;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.Message;
import org.springframework.stereotype.Component;

/**
 * @Desc: ""
 * @Author: caixiang
 * @DATE: 2021/6/22 15:36
 */
@Component
public class DeadLetterQueueReceived {
//    @RabbitListener(
//            bindings = @QueueBinding(
//                    value = @Queue(value="Dead_Letter_Queue_PID00B",durable = "true"),
//                    exchange = @Exchange(name = "Dead_Letter_Exchange",durable = "true",type = ExchangeTypes.DIRECT,ignoreDeclarationExceptions = "true"),
//                    key = "Dead_Letter_Queue_PID00B_RoutingKey"
//            )
//    )


    @RabbitListener(queues = ConfigOfDeadLetterQueue.Dead_Letter_Queue)
    @RabbitHandler
    public void deadLetterQueue(Message<?> message, Channel channel)throws Exception{

        System.out.println("线程名"+Thread.currentThread().hashCode()+"==============Dead_Letter_Exchange=================,"+",attr2"+message.getHeaders().get("attr2"));

        Thread.sleep(500);
        Long deliveryTag = (Long)message.getHeaders().get(AmqpHeaders.DELIVERY_TAG);

        //throw new Exception("12331");

        //channel.basicNack(deliveryTag,false,true);
        channel.basicAck(deliveryTag,false);
    }
}
